package com.mobile.collect.view;

import android.app.Activity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.widget.TextView;

import com.mobile.collect.R;

import java.util.ArrayList;
import java.util.List;

import cn.droidlover.xdroidmvp.base.BaseRecyclerAdapter;
import cn.droidlover.xdroidmvp.base.ListViewItemClickListener;
import cn.droidlover.xdroidmvp.base.RecyclerViewHolder;

/**
 * 类名: KeyBroadPop
 * 作者: 李学伟
 * 日期: 2020年09月22日 16:39
 * 描述: dialog_keybroad
 */
public class KeyBroadPop extends InputDialog  {
    RecyclerView lattersView;
    RecyclerView numberView;
    RecyclerView specialView;
    BaseRecyclerAdapter<String> lattersAdapter;
    BaseRecyclerAdapter<String> numberAdapter;
    BaseRecyclerAdapter<String> specialAdapter;

    public KeyBroadPop(Activity context, TextView textView, String label,  String oldTxt, InputCompleteListener listener, int maxCount) {
        super(context, label,oldTxt, listener, R.layout.dialog_keybroad, maxCount);
    }

    @Override
    protected void initViews() {
        super.initViews();
        lattersView = findViewById(R.id.lattersView);
        numberView = findViewById(R.id.numberView);
        specialView = findViewById(R.id.specialView);
        lattersView.setLayoutManager(new GridLayoutManager(context, 6));
        numberView.setLayoutManager(new GridLayoutManager(context, 5));
        specialView.setLayoutManager(new GridLayoutManager(context, 4));

        lattersAdapter = new BaseRecyclerAdapter<String>(context) {
            @Override
            public int getItemLayoutId(int viewType) {
                return R.layout.item_latters;
            }

            @Override
            public void bindData(RecyclerViewHolder holder, int position) {
                super.bindData(holder, position);
                holder.setText(R.id.valueTv, getItemByPosition(position));
            }
        };
        lattersView.setAdapter(lattersAdapter);
        lattersAdapter.addList(true, getLatters());

        numberAdapter = new BaseRecyclerAdapter<String>(context) {
            @Override
            public int getItemLayoutId(int viewType) {
                return R.layout.item_latters;
            }

            @Override
            public void bindData(RecyclerViewHolder holder, int position) {
                super.bindData(holder, position);
                holder.setText(R.id.valueTv, getItemByPosition(position));
            }
        };
        numberView.setAdapter(numberAdapter);
        numberAdapter.addList(true, getNumbers());

        specialAdapter = new BaseRecyclerAdapter<String>(context) {
            @Override
            public int getItemLayoutId(int viewType) {
                return R.layout.item_latters;
            }

            @Override
            public void bindData(RecyclerViewHolder holder, int position) {
                super.bindData(holder, position);
                holder.setText(R.id.valueTv, getItemByPosition(position));
            }
        };
        specialView.setAdapter(specialAdapter);
        specialAdapter.addList(true, getSpecials());

        specialAdapter.setItemClickListener(new ListViewItemClickListener() {
            @Override
            public void itemClick(int position) {
                if (TextUtils.equals("删除",specialAdapter.getItemByPosition(position))) {
                    del();
                }else{
                    appendText(specialAdapter.getItemByPosition(position));
                }
            }
        });
        numberAdapter.setItemClickListener(new ListViewItemClickListener() {
            @Override
            public void itemClick(int position) {
                appendText(numberAdapter.getItemByPosition(position));
            }
        });

        lattersAdapter.setItemClickListener(new ListViewItemClickListener() {
            @Override
            public void itemClick(int position) {
                appendText(lattersAdapter.getItemByPosition(position));
            }
        });

    }



    private List<String> getLatters() {
        List<String> datas = new ArrayList<>();
        datas.add("A");
        datas.add("B");
        datas.add("C");
        datas.add("D");
        datas.add("E");
        datas.add("F");
        datas.add("K");
        datas.add("P");
        datas.add("R");
        datas.add("S");
        datas.add("T");
        datas.add("V");
        return datas;
    }

    private List<String> getNumbers() {
        List<String> datas = new ArrayList<>();
        for (int i = 1; i <=10; i++) {
            datas.add(String.valueOf(i%10));
        }
        return datas;
    }

    private List<String> getSpecials() {
        List<String> datas = new ArrayList<>();
        datas.add("-");
        datas.add(".");
        datas.add("/");
        datas.add("删除");
        return datas;
    }

}
